(function () {
    "use strict";

    angular.module('core').factory('operacaoVendaService', factory);
    factory.$inject = ['$http', '$q'];

    function factory($http, $q) {

        var _get = function (id) {
            var deferred = $q.defer();
            $http.post('/operacaovenda/get', id)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        var _prepareNew = function () {
            var deferred = $q.defer();
            $http.post('/operacaovenda/prepareNew')
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        var _prepareNewCondicaoPagamento = function (item) {
            var deferred = $q.defer();
            $http.post('/operacaovenda/PrepareNewCondicaoPagamento',item)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        var _getAll = function (args) {
            var deferred = $q.defer();
            $http.post('/operacaovenda/getall', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _count = function (args) {
            var deferred = $q.defer();
            $http.post('/operacaovenda/count', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        var _save = function (item) {
            var deferred = $q.defer();
            $http.post('/operacaovenda/save', item)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _delete = function (id) {
            var deferred = $q.defer();
            $http.post('/operacaovenda/delete', id)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        return {
            get: _get,
            getAll: _getAll,
            count: _count,
            save: _save,
            delete: _delete,
            prepareNew: _prepareNew,
            prepareNewCondicaoPagamento: _prepareNewCondicaoPagamento
        };
    }

})();


